package o;

import android.content.Context;
import android.os.Build.VERSION;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.packagemanager.api.bean.ProfileTask;
import com.huawei.appgallery.packagemanager.impl.utils.HMFUtils;
import com.huawei.hmf.annotation.ApiDefine;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@ApiDefine(uri = cnt.class)
public class coo implements cnt {
    private static int ˊ = -1;
    private static final ThreadPoolExecutor ˎ = new ThreadPoolExecutor(2, 4, 10, TimeUnit.SECONDS, new LinkedBlockingQueue(), new cqd("AppProfile"));
    public static final Map<String, ProfileTask> ॱ = new ConcurrentHashMap();

    private static boolean ˏ(Context context) {
        if (ˊ == -1) {
            if (((((cnw) HMFUtils.ˊ(cnw.class)).ˋ(context) & 2) != 0 ? 1 : 0) == 0 || VERSION.SDK_INT < 28) {
                ˊ = 0;
                cnu.ˏ.ˋ("AppProfileManagerImpl", "APP_PROFILE_UNSUPPORT");
                return false;
            }
            ˊ = 1;
            cnu.ˏ.ˋ("AppProfileManagerImpl", "APP_PROFILE_SUPPORT");
            return true;
        } else if (ˊ == 1) {
            return true;
        } else {
            return false;
        }
    }

    public static void ˎ(String str) {
        ॱ.remove(str);
    }

    public boolean ˊ(Context context) {
        return ˏ(context);
    }

    public ProfileTask ˊ(Context context, @NonNull String str, @NonNull int i, @NonNull String str2, @NonNull String str3) {
        if (!ˊ(context)) {
            return null;
        }
        ProfileTask profileTask;
        cor ˎ = cor.ˎ(context);
        ˎ.ॱ();
        List ˊ = ˎ.ˊ(str, String.valueOf(i), str2, str3);
        if (ˊ.isEmpty()) {
            profileTask = new ProfileTask();
            profileTask.packageName = str;
            profileTask.versionCode = i;
            profileTask.profileUrl = str2;
            profileTask.sha256 = str3;
            profileTask.status = 1;
            ˎ.ˏ(profileTask);
        } else {
            profileTask = (ProfileTask) ˊ.get(0);
            if (profileTask.status >= 1) {
                ˎ.ˏ();
                return profileTask;
            }
        }
        ˎ.ˏ();
        ॱ.put(profileTask.packageName, profileTask);
        new cot(context).executeOnExecutor(ˎ, new ProfileTask[]{profileTask});
        return profileTask;
    }

    public void ˋ(@NonNull Context context, @NonNull String str) {
        if (ˊ(context)) {
            new cou(context, str).executeOnExecutor(ˎ, new Void[0]);
        }
    }

    public ProfileTask ˊ(@NonNull Context context, @NonNull String str, @NonNull int i) {
        if (!ˊ(context)) {
            return null;
        }
        cor ˎ = cor.ˎ(context);
        ˎ.ॱ();
        List<ProfileTask> ˊ = ˎ.ˊ(str, String.valueOf(i), null, null);
        ˎ.ˏ();
        for (ProfileTask profileTask : ˊ) {
            if (profileTask.status == 2) {
                Object obj = profileTask.profilePath;
                if (!TextUtils.isEmpty(obj) && new File(obj).exists()) {
                    return profileTask;
                }
            }
        }
        return null;
    }
}
